package beans;
import java.util.Date;
import java.util.HashMap;
import java.util.Map.Entry;
import org.hibernate.*;
import domain.Vehicle;
/**
 * VehicleQuery 
 */
public class VehicleQuery extends AbstractPagedQuery<Vehicle> {
	/**
	 * 车辆编号 
	 */
	private String numCode;
	/**
	 * 车辆类型 
	 */
	private String carType;
	/**
	 * 车牌号 
	 */
	private String registNumber;
	/**
	 * 征费吨位 
	 */
	private Double chargeShipGRT;
	/**
	 * 车辆名称 
	 */
	private String carName;
	/**
	 * 车辆状态 
	 */
	private String carStatus;
	/**
	 * 容积 
	 */
	private Double carVolume;
	/**
	 * 颜色 
	 */
	private String carColor;
	/**
	 * 构建hibernate Query对象.需要构造查询sql语句,并将查询参数设置到Query对象中.
	 * @param pSession hibernate session
	 * @param pIsQueryTotalCount 是否是构造查询纪录总数目的Query.
	 * @return hibernate Query
	 */
	public Query buildQuery(Session pSession, boolean pIsQueryTotalCount) {
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		if (pIsQueryTotalCount) {// 查询总数
		    sql.append("select count(*) from Vehicle t where 1=1 ");
		} else {
	    	sql.append(" from Vehicle t where 1=1 ");
	    }
	    	if (null != numCode) {
	        queryParams.put("numCode", "%"+numCode+"%");
	        sql.append(" and t.numCode like:numCode ");
	    }
	    	if (null != carType) {
	        queryParams.put("carType", "%"+carType+"%");
	        sql.append(" and t.carType like:carType ");
	    }
	    	if (null != registNumber) {
	        queryParams.put("registNumber", "%"+registNumber+"%");
	        sql.append(" and t.registNumber like:registNumber ");
	    }
	    	if (null != chargeShipGRT) {
	        queryParams.put("chargeShipGRT", chargeShipGRT);
			sql.append(" and t.chargeShipGRT =:chargeShipGRT ");
	    }
	    	if (null != carName) {
	        queryParams.put("carName", "%"+carName+"%");
	        sql.append(" and t.carName like:carName ");
	    }
	    	if (null != carStatus) {
	        queryParams.put("carStatus", "%"+carStatus+"%");
	        sql.append(" and t.carStatus like:carStatus ");
	    }
	    	if (null != carVolume) {
	        queryParams.put("carVolume", carVolume);
			sql.append(" and t.carVolume =:carVolume ");
	    }
	    	if (null != carColor) {
	        queryParams.put("carColor", "%"+carColor+"%");
	        sql.append(" and t.carColor like:carColor ");
	    }
	    Query query = pSession.createQuery(sql.toString());
	    for (Entry<String, Object> entry : queryParams.entrySet()) {
	        query.setParameter(entry.getKey(), queryParams.get(entry.getKey()));
	    }
	    return query;
	}
	/**
	 * @return String 
	 */
	public String getNumCode(){
		return numCode;
	}
	/**
	 * @param pNumCode 
	 */
	public void setNumCode(String pNumCode){
		numCode=pNumCode;
	}
	/**
	 * @return String 
	 */
	public String getCarType(){
		return carType;
	}
	/**
	 * @param pCarType 
	 */
	public void setCarType(String pCarType){
		carType=pCarType;
	}
	/**
	 * @return String 
	 */
	public String getRegistNumber(){
		return registNumber;
	}
	/**
	 * @param pRegistNumber 
	 */
	public void setRegistNumber(String pRegistNumber){
		registNumber=pRegistNumber;
	}
	/**
	 * @return Double 
	 */
	public Double getChargeShipGRT(){
		return chargeShipGRT;
	}
	/**
	 * @param pChargeShipGRT 
	 */
	public void setChargeShipGRT(Double pChargeShipGRT){
		chargeShipGRT=pChargeShipGRT;
	}
	/**
	 * @return String 
	 */
	public String getCarName(){
		return carName;
	}
	/**
	 * @param pCarName 
	 */
	public void setCarName(String pCarName){
		carName=pCarName;
	}
	/**
	 * @return String 
	 */
	public String getCarStatus(){
		return carStatus;
	}
	/**
	 * @param pCarStatus 
	 */
	public void setCarStatus(String pCarStatus){
		carStatus=pCarStatus;
	}
	/**
	 * @return Double 
	 */
	public Double getCarVolume(){
		return carVolume;
	}
	/**
	 * @param pCarVolume 
	 */
	public void setCarVolume(Double pCarVolume){
		carVolume=pCarVolume;
	}
	/**
	 * @return String 
	 */
	public String getCarColor(){
		return carColor;
	}
	/**
	 * @param pCarColor 
	 */
	public void setCarColor(String pCarColor){
		carColor=pCarColor;
	}
}
